import java.sql.*;
import javax.sql.*;

public class DatabaseSample{

	public static void run() {
		System.out.println("MySQL Connect Example.");
		Connection conn = null;
		String url = "jdbc:mysql://localhost:3306/";
		String dbName = "test";
		String driver = "com.mysql.jdbc.Driver";
		String userName = "root";
		String password = "";

		String query = "Select * FROM users";

		try {
			Class.forName(driver).newInstance();
			conn = DriverManager
					.getConnection(url + dbName, userName, password);
			System.out.println("Connected to the database");

			 Statement st = conn.createStatement();
			 ResultSet res = st.executeQuery("SELECT * FROM  users");
			 System.out.println("Names in DB:");
			 while (res.next()) {
				 String s = res.getString("name");
				 System.out.println(s);
			 }
			
			
			conn.close();
			System.out.println("Disconnected from database");
		} catch (Exception e) {
			e.printStackTrace();
		}
	} // end main

} // end class